{
  LW Tool -- LightWave Mouse Tools

  Based on lwtool.h which is:
  Copyright 1999, NewTek, Inc.
}

{
  Copyright 2012, Jameel Halabi

  This unit is part of the BlaiseWave wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


unit LW_Tool;

{$mode objfpc}{$H+}

interface

uses
  LW_Types ,
  LW_XPanel;

const
  LWWIRE_SOLID    = 0;
  LWWIRE_DASH     = 1;

  LWWIRE_ABSOLUTE =   0;
  LWWIRE_RELATIVE = 100;
  LWWIRE_SCREEN   = 101;

  LWWIRE_TEXT_L = 0;
  LWWIRE_TEXT_C = 1;
  LWWIRE_TEXT_R = 2;

  LWTOOLF_CONSTRAIN  = 1 shl 0;
  LWTOOLF_CONS_X     = 1 shl 1;
  LWTOOLF_CONS_Y     = 1 shl 2;
  LWTOOLF_ALT_BUTTON = 1 shl 3;
  LWTOOLF_MULTICLICK = 1 shl 4;

  LWT_DIRTY_WIREFRAME = 1 shl 0;
  LWT_DIRTY_HELPTEXT  = 1 shl 1;

  LWT_EVENT_DROP            = 0;
  LWT_EVENT_RESET           = 1;
  LWT_EVENT_ACTIVATE        = 2;
  LWT_EVENT_EXTERNAL_ACTION = 3;

type
  {
    The functions in a wire draw access struct allows a tool to draw a
    wireframe representation of itself.  The 'moveTo' function selects
    the line type, and the drawing functions can provide coordinates that
    are absolute or relative in model or screen space.
  }
  PLWWireDrawAccess = ^TLWWireDrawAccess;
  TLWWireDrawAccess = record
    // pointer to private data used by the implementation.
    Data   : Pointer;

    // move cursor to a specific position without drawing.
    // returns 0 if the linemode is not supported
    MoveTo : procedure
             (      Data          : Pointer   ;
                    Pos           : TLWFVector;
                    LineMode      : Integer   ) ;

    // draw a line from the current cursor position to a given position.
    LineTo : procedure
             (      Data          : Pointer   ;
                    Pos           : TLWFVector;
                    CoordSystem   : Integer   ) ;

    // draw a spline from the current cursor position.
    Spline : procedure
             (      Data          : Pointer   ;
                    CP0, CP1, CP2 : TLWFVector;
                    CoordSystem   : Integer   ) ;

    // draw a circle with the given radius around the current point.
    Circle : procedure
             (      Data          : Pointer   ;
                    Radius        : Double    ;
                    CoordSystem   : Integer   ) ;

    // 0, 1, or 2 for orthogonal views, -1 for a perspective view.
    Axis   : Integer;

    // draw the specified text at the current position
    Text   : procedure
             (      Data          : Pointer   ;
              const TextLine      : PChar     ;
                    Justify       : Integer   ) ;

    PXScale : Double;
  end;

  {
    Mouse events in LightWave viewports occur in 3D space.

    PosRaw     Event position in 3D space.  Naturally this occurs in
    PosSnap    some view plane.  One value is snapped to the nearest
               grid intersection in 3D while the other is not.

    DeltaRaw   Vector from the initial mouse-down event to the current
    DeltaSnap  event location.  These are the difference between the
               current 'pos' values and the first one.

    DX, DY     Screen movement in pixels.  This is the total raw mouse
               offset from the starting position.

    PXRaw/Snap Parametric translation values.  These are the mouse
    PYRaw/Snap offsets converted to values in model-space.  They provide
               a method for computing abstract distance measures from
               left/right and up/down mouse movement roughly scaled to
               the magnification of the viewport.

    Axis       Event axis.  All the points under the mouse location
               are along this axis through 'pos'.

    AX         Screen coordinate system.  The ax vector points to the
    AY         right on the screen, the ay vector points up the screen
    AZ         and the az vector points into the screen.  Movement along
               each vector corresponds to approximately one pixel of
               screen-space movement.

    PortAxis   View axis which is 0, 1 or 2 for orthogonal views.  It
               is -1 for perspective views.

    ViewNumber Which window view the the event came from (0 to 3).
  }
  PLWToolEvent = ^TLWToolEvent;
  TLWToolEvent = record
    PosRaw     ,
    PosSnap    : TLWDVector; // Snap same as Raw in Layout

    DeltaRaw   ,
    DeltaSnap  : TLWDVector; // Snap same as Raw in Layout

    Axis       : TLWDVector;
    AX, AY, AZ : TLWDVector;

    PXRaw      ,             // Modeler Only
    PXSnap     : Double    ; // Modeler Only

    PYRaw      ,             // Modeler Only
    PYSnap     : Double    ; // Modeler Only

    DX, DY     : Integer   ;
    PortAxis   : Integer   ;
    Flags      : Integer   ;
    ViewNumber : Integer   ; // New For LightWave 8.
  end;

  {
    The 'flags' field can have a number of bits set to indicate the type of
    mouse event.

    CONSTRAIN  constrained action, activated by a standard key or mouse
               combination.

    CONS_X     direction of constraint for orthogonal moves.  Initially
    CONS_Y     neither bit is set, but as the user moves enough to select a
               primary direction, one or the other will be set.

    ALT_BUTTON alternate mouse button event, usually the right button.

    MULTICLICK multiclick sequence event.
  }

  {
    A LightWave viewport tool has the following handler functions.

    Done     destroy the instance when the user discards the tool.

    Draw     display a wireframe representation of the tool in a 3D
             viewport.  Typically this draws the handles.

    Help     return a text string to be displayed as a help tip for
             this tool.

    Dirty    return flag bit if either the wireframe or help string
             need to be refreshed.

    Count    return the number of handles.  If zero, then 'start' is
             used to set the initial handle point.

    Handle   return the 3D location and priority of handle 'i', or zero
             if the handle is currently invalid.

    Start    take an initial mouse-down position and return the index
             of the handle that should be dragged.

    Adjust   drag the given handle to a new location and return the
             index of the handle that should continue being dragged
             (often the same as the input).

    Down     process a mouse-down event.  If this function returns
             false, handle processing will be done instead of raw
             mouse event processing.

    Move     process a mouse-move event.  This is only called if the
             down function returned true.

    Up       process a mouse-up event.  This is only called if the down
             function returned true.

    Event    process a general event: DROP, RESET or ACTIVATE

    Panel    create and return a view-type xPanel for the tool instance.

    Undo     gets called when the user requests to perform an undo operation.
             return true to allow Lightwave's undo system to take care of it,
             or false to block it so that the tool can handle it accordingly.

    Redo     gets called when the user requests to perform a redo operation.
             return true to allow lightwave's undo system to take care of it,
             or false to block it so that the tool can handle it accordingly.
  }
  PLWToolFuncs = ^TLWToolFuncs;
  TLWToolFuncs = record
    Done   : procedure
             (      Instance   : PLWInstance      ) ;
    Draw   : procedure
             (      Instance   : PLWInstance      ;
                    DrawAccess : PLWWireDrawAccess) ;
    Help   : function
             (      Instance   : PLWInstance      ;
                    EventInfo  : PLWToolEvent     ) : PChar    ;
    Dirty  : function
             (      Instance   : PLWInstance      ) : Integer  ;
    Count  : function
             (      Instance   : PLWInstance      ;
                    EventInfo  : PLWToolEvent     ) : Integer  ;
    Handle : function
             (      Instance   : PLWInstance      ;
                    EventInfo  : PLWToolEvent     ;
                    I          : Integer          ;
                    Pos        : TLWDVector       ) : Integer  ;
    Start  : function
             (      Instance   : PLWInstance      ;
                    EventInfo  : PLWToolEvent     ) : Integer  ;
    Adjust : function
             (      Instance   : PLWInstance      ;
                    EventInfo  : PLWToolEvent     ;
                    I          : Integer          ) : Integer  ;
    Down   : function
             (      Instance   : PLWInstance      ;
                    EventInfo  : PLWToolEvent     ) : Integer  ;
    Move   : procedure
             (      Instance   : PLWInstance      ;
                    EventInfo  : PLWToolEvent     ) ;
    Up     : procedure
             (      Instance   : PLWInstance      ;
                    EventInfo  : PLWToolEvent     ) ;
    Event  : procedure
             (      Instance   : PLWInstance      ;
                    Code       : Integer          ) ;
    Panel  : function
             (      Instance   : PLWInstance      ) : PLWXPanel;
    Undo   : function
             (      Instance   : PLWInstance      ) : Integer  ;
    Redo   : function
             (      Instance   : PLWInstance      ) : Integer  ;
  end;

  PLWTool = ^TLWTool;
  TLWTool = record
    Instance : PLWInstance ;
    Tool     : PLWToolFuncs;
  end;

implementation

end.

